package com.zzl.car.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zzl.car.entity.Notice;
import com.zzl.car.entity.User;
import com.zzl.car.exception.ZdpException;
import com.zzl.car.mapper.ZzwNoticeMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service
public class ZzwNoticeService {
    @Autowired
    private ZzwNoticeMapper noticeMapper;

    // 获取公告信息
    public PageInfo<Notice> getNotice(String title, Integer state, Integer currentPage){
        int pageAmount = 8;
        PageInfo<Notice> pageInfo = null;
        List<Notice> notice = new ArrayList<>();

        PageHelper.startPage(currentPage,pageAmount);
        notice = noticeMapper.getNotice(title,state);

        pageInfo = new PageInfo<>(notice);
        pageInfo.setList(notice);

        return pageInfo;
    }

    // 删除公告
    public String deleteNotice(Integer id){
        if(noticeMapper.deleteNotice(id) > 0)
            return "1";
        else
            throw new ZdpException(2890,"删除失败");
    }
    // 添加公告
    public String addNotice(Notice notice){
        if(noticeMapper.addNotice(notice) > 0)
            return "1";
        else
            throw new ZdpException(2890,"添加失败");
    }
    // 修改公告
    public String modifyNotice(Notice notice){
        if(noticeMapper.modifyNotice(notice) > 0)
            return "1";
        else
            throw new ZdpException(2890,"修改失败");
    }

}
